package consultan.vanke.com.fragment;

import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import butterknife.BindView;
import butterknife.OnClick;
import consultan.vanke.com.R;
import consultan.vanke.com.utils.SimpleToolbar;

import static com.bytedance.sdk.account.open.aweme.utils.ViewUtils.getStatusBarHeight;
import static consultan.vanke.com.utils.StatusBarUtil.setPaddingTop;
import static consultan.vanke.com.utils.StatusBarUtil.setRootView;


public class ChongzhiFragment extends BaseFragment {
    @BindView(R.id.simple_toolbar)
    SimpleToolbar simpleToolbar;
    @BindView(R.id.simple_toolbar_main)
    ConstraintLayout simpleToolbarMain;
    @BindView(R.id.view_line)
    View viewLine;
    @BindView(R.id.lienar_top)
    LinearLayout lienarTop;
    @BindView(R.id.btn_login)
    Button btnLogin;
    @BindView(R.id.rel_all)
    RelativeLayout relAll;
    private View inflate;
    private boolean isfristshow = true;
    private PopupWindow popupWindow;
    private View def_sort;

    @Override
    protected void initViews() {
        simpleToolbar.setMainBg(getResources().getColor(R.color.white_color));
        simpleToolbar.setMainTitle("账户充值");
        def_sort = LayoutInflater.from(_mActivity).inflate(R.layout.cz_sort_def, null);
        ImageView img_del = def_sort.findViewById(R.id.img_del);
        img_del.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                popupWindow.dismiss();
            }
        });
        popupWindow = new PopupWindow(def_sort, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);
        popupWindow.setOutsideTouchable(true);
        popupWindow.setBackgroundDrawable(new BitmapDrawable());
        popupWindow.setFocusable(true);// 点击空白处时，隐藏掉pop窗口
    }

    @Override
    protected void initDatas() {
    }

    @Override
    protected void initEvents() {
        simpleToolbar.setLeftTitleClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                pop();
            }
        });
        simpleToolbar.setRightTitleAginClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                start(new ChongzhiFragment());
            }
        });
    }

    @Override
    protected View initContentView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        inflate = View.inflate(_mActivity, R.layout.chongzhi_fragment, null);
        return inflate;
    }

    @Override
    public void onSupportVisible() {
        super.onSupportVisible();
        ViewGroup decorView = (ViewGroup) _mActivity.getWindow().getDecorView();
        View fakeStatusBarView = new View(_mActivity);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(_mActivity) + 3);
        fakeStatusBarView.setLayoutParams(params);
        fakeStatusBarView.setBackground(getResources().getDrawable(R.drawable.bg_white));
        fakeStatusBarView.setId(android.R.id.custom);
        decorView.addView(fakeStatusBarView);
        setRootView(_mActivity, false);
        if (isfristshow) {
            setPaddingTop(_mActivity, simpleToolbar);
            isfristshow = false;
        }
        setStatusBarColors(getResources().getColor(R.color.white_color), true);
    }

    @OnClick({R.id.btn_login})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_login:
                if (popupWindow.isShowing()) {
                    popupWindow.dismiss();
                    return;
                }
                popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
                    @Override
                    public void onDismiss() {
//                        imgNorsort.setBackgroundDrawable(getResources().getDrawable(R.mipmap.asset_buttom));
                    }
                });
                popupWindow.showAtLocation(inflate.findViewById(R.id.rel_all), Gravity.BOTTOM, 0, 0);
                break;
        }

    }
}
